#include "kit/event/EventCreator.hpp"
#include "kit/event/BroadcastEvent.hpp"
#include "kit/event/FollowEvent.hpp"
#include "kit/event/PrivateMsgEvent.hpp"
#include "kit/event/StatusUpdateEvent.hpp"
#include "kit/event/UnfollowEvent.hpp"

namespace KitEvent
{
    EventCreator::EventCreator()
    {
        // add all the event you want to handle here
        _eventChain.push_back(new BroadcastEvent());
        _eventChain.push_back(new FollowEvent());
        _eventChain.push_back(new PrivateMsgEvent());
        _eventChain.push_back(new StatusUpdateEvent());
        _eventChain.push_back(new UnfollowEvent());
    }

    EventCreator::~EventCreator()
    {
    	// remove events
        for(int i = 0; i < _eventChain.size(); ++i)
            delete _eventChain[i];
    }

    Event * EventCreator::createEvent(KitMessage::Message * iMessage)
    {
    	// ask events if some of them is able to handle the message
        for(int i = 0; i < _eventChain.size(); ++i)
        {
            if(_eventChain[i]->isMyEvent(iMessage))
                return _eventChain[i]->makeCopy(iMessage);
        }
        return NULL;
    }
}
